package com.cupk.service.impl;

import com.cupk.mapper.BookMapper;
import com.cupk.pojo.Book;
import com.cupk.service.BookService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Primary;
import org.springframework.stereotype.Service;
import java.util.List;

@Service
@Primary//优先使用该实现类
public class BookServiceImpl implements BookService {
    @Autowired(required = false)//根据类型注入（传值）
    private BookMapper bookMapper;
    @Override
    public List<Book> findAllBooks() {
        return bookMapper.findAllBooks();
    }

    @Override
    public Book findBookById(Integer id) {
        return bookMapper.findBookById(id);
    }

    @Override
    public int updateBook(Book book) {
        return bookMapper.updateBook(book);
    }

    @Override
    public int insertBook(Book book) {
        return bookMapper.insertBook(book);
    }

    @Override
    public int deleteBookById(Integer id) {
        return bookMapper.deleteBookById(id);
    }

    @Override
    public List<Book> findBookByStr(String searchStr) {
        return bookMapper.findBookByStr(searchStr);
    }

    @Override
    public int deleteBooks(Integer[] ids) {
        int count=0;
        for (Integer id:ids){
            count+=bookMapper.deleteBookById(id);//逐个删除图书
        }
        return count;
    }
}
